#!/bin/bash

read -p "请输入版本(v10.15.0):" VERSION
#VERSION=v10.15.0
DISTRO=linux-x64
mkdir -p /usr/local/lib/node/$VERSION
#wget https://nodejs.org/dist/v18.13.0/node-v18.13.0-linux-x64.tar.xz
if [ ! -f /usr/bin/wget ]; then
  yum install wget -y
fi
wget https://nodejs.org/dist/$VERSION/node-$VERSION-linux-x64.tar.xz
tar -xJvf node-$VERSION-$DISTRO.tar.xz -C /usr/local/lib/node/$VERSION


echo "export PATH=/usr/local/lib/node/$VERSION/node-$VERSION-$DISTRO/bin:$PATH" > /etc/profile.d/nodejs.sh
#source /etc/profile.d/nodejs.sh


if [ ! -d /data/node ]; then
  mkdir -p /data/node
fi
mv node-$VERSION-$DISTRO.tar.xz /data/node/


echo -e "\n\n\n\033[33mStep1:\033[31m execute \"source /etc/profile.d/nodejs.sh\" OR reboot\033[0m"
echo -e "\n\n\n\033[33mStep2: \033[31mTo Test\n\033[32mnode -v\nnpm version\nnpx -v\033[0m"
